package com.llyb.controller;

import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.chat.response.ChatResponse;
import dev.langchain4j.model.output.TokenUsage;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class LowApiController {

    @Resource(name = "qwen")
    private ChatModel chatModelQwen;

    @Resource(name = "deepseek")
    private ChatModel chatModelDeepseek;

    @GetMapping("/lowapi/api01")
    public String hello(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){
        String result = chatModelQwen.chat(prompt);
        System.out.println(result);
        return result;
    }

    @GetMapping("/lowapi/api02")
    public String deepseekHello(@RequestParam(value = "prompt",defaultValue = "你是谁") String prompt){
        ChatResponse chatResponse = chatModelDeepseek.chat(UserMessage.from(prompt));

        String text = chatResponse.aiMessage().text();
        System.out.println("返回的结果"+text);

        TokenUsage tokenUsage = chatResponse.tokenUsage();
        System.out.println("花费的token"+tokenUsage);

        return text;
    }


}
